//
//  YWWaitMeterReadingTableViewCell.m
//  maintain
//
//  Created by 烟雨云渊 on 2017/4/26.
//  Copyright © 2017年 ewin. All rights reserved.
//

#import "YWWaitMeterReadingTableViewCell.h"
#import "Masonry.h"
#import "UIColor+CustomColors.h"
#import "YWCommonTool.h"
#import "YWMacro.h"
#import "YYLabel.h"
#import "YWEquipment.h"
#import "YWLocation.h"
#import "YWBuildingManager.h"

@interface YWWaitMeterReadingTableViewCell()
@property (nonatomic, strong) YYLabel * equNameLabel;
@property (nonatomic, strong) YYLabel * locationLabel;
@property (nonatomic, strong) YYLabel * ownCodeLabel;
@end

@implementation YWWaitMeterReadingTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.layer.shouldRasterize = YES;
        self.layer.rasterizationScale = [UIScreen mainScreen].scale;
        [self setUpSubviews];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.clipsToBounds = YES;
    }
    return self;
}

- (void)setEquipment:(YWEquipment *)equipment{
    _equipment = equipment;
    _equNameLabel.attributedText = [YWCommonTool attributedTextWithFirstText:@"设备：" firstColor:[UIColor customTextGrayBlackColor] secondText:_equipment.equipmentName.length>0?_equipment.equipmentName:@"未知设备" secondColor:[UIColor blackColor] font:kContentFont];
    _ownCodeLabel.text = equipment.ownCode;
    NSString * locationStr = [[YWBuildingManager shareManager] locationWithId:_equipment.locationId].locationName;
    _locationLabel.attributedText = [YWCommonTool attributedTextWithFirstText:@"位置: " firstColor:[UIColor customTextGrayBlackColor] secondText:locationStr.length>0?locationStr:@"未知位置" secondColor:[UIColor blackColor] font:kContentFont];
    self.locationLabel.preferredMaxLayoutWidth = self.locationLabel.frame.size.width;
}

- (void)setUpSubviews{
    [self.equNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(6);
        make.left.mas_equalTo(self.contentView).offset(8);
        make.right.mas_equalTo(self.ownCodeLabel.mas_left).offset(-8);
    }];
    
    [self.ownCodeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(6);
//        make.left.mas_equalTo(self.equNameLabel.mas_right).offset(8);
        make.right.mas_equalTo(self.contentView).offset(-8);
    }];
    
    [self.locationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.equNameLabel.mas_bottom).offset(6);
        make.left.mas_equalTo(self.contentView).offset(8);
        make.right.mas_equalTo(self.contentView).offset(-8);
        make.bottom.mas_equalTo(self.contentView).offset(-8);
    }];
}

- (YYLabel *)equNameLabel{
    if (!_equNameLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        _equNameLabel = label;
        [self.contentView addSubview:_equNameLabel];
    }
    return _equNameLabel;
}

- (YYLabel *)ownCodeLabel{
    if (!_ownCodeLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        label.font = KSmallContentFont;
        label.textColor = [UIColor customTextGrayColor];
        _ownCodeLabel = label;
        [self.contentView addSubview:_ownCodeLabel];
    }
    return _ownCodeLabel;
}


- (YYLabel *)locationLabel{
    if (!_locationLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        label.numberOfLines = 0;
        _locationLabel = label;
        [self.contentView addSubview:_locationLabel];
    }
    return _locationLabel;
}

@end
